package filters;

import helpers.UrlHelper;

import java.io.IOException;
import java.net.URLDecoder;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import admin.models.StaffModel;

import entities.SiteConfig;
import entities.Staff;
import entities.User;


import systems.ConfigSystem;

import models.UserModel;

public final class UrlFilter implements Filter {
	static {
		
	}
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
		HttpServletRequest req = (HttpServletRequest) request;
		HttpServletResponse resp = (HttpServletResponse) response;
		SiteConfig config = ConfigSystem.getConfigs();
		
		
		//HttpSession session = req.getSession();
		//Get user
		User user = null;
		/*if (session.getAttribute("user_logged_in") != null) {
			user = (User) session.getAttribute("user_logged_in");
		}*/
		
		//Get Staff
		Staff staff = null;
		/*if (session.getAttribute("staff_logged_in") != null) {
			staff = (Staff) session.getAttribute("staff_logged_in");
		}*/
		
		request.setAttribute("user_logged_in", user);
		request.setAttribute("staff_logged_in", staff);
		
		request.setAttribute("config", config);
		try {
			chain.doFilter(request, response);
		} catch (Exception e) {
			// TODO: handle exception
		}
		
	}

	public void destroy() {

	}

	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
	}
}